
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ 4.0 (/ (* 4.0 (- x z)) y)))
double code(double x, double y, double z) {
return 4.0 + ((4.0 * (x - z)) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 4.0d0 + ((4.0d0 * (x - z)) / y)
end function
public static double code(double x, double y, double z) {
return 4.0 + ((4.0 * (x - z)) / y);
}
def code(x, y, z): return 4.0 + ((4.0 * (x - z)) / y)
function code(x, y, z) return Float64(4.0 + Float64(Float64(4.0 * Float64(x - z)) / y)) end
function tmp = code(x, y, z) tmp = 4.0 + ((4.0 * (x - z)) / y); end
code[x_, y_, z_] := N[(4.0 + N[(N[(4.0 * N[(x - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + \frac{4 \cdot \left(x - z\right)}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
associate-*r/100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -3.6e+174)
(and (not (<= z -1.85e+61))
(or (<= z -0.000135)
(not
(or (<= z 1.5e+91)
(and (not (<= z 3.7e+111)) (<= z 1.06e+171)))))))
(+ (* -4.0 (/ z y)) 1.0)
(+ 4.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.6e+174) || (!(z <= -1.85e+61) && ((z <= -0.000135) || !((z <= 1.5e+91) || (!(z <= 3.7e+111) && (z <= 1.06e+171)))))) {
tmp = (-4.0 * (z / y)) + 1.0;
} else {
tmp = 4.0 + (4.0 * (x / y));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-3.6d+174)) .or. (.not. (z <= (-1.85d+61))) .and. (z <= (-0.000135d0)) .or. (.not. (z <= 1.5d+91) .or. (.not. (z <= 3.7d+111)) .and. (z <= 1.06d+171))) then
tmp = ((-4.0d0) * (z / y)) + 1.0d0
else
tmp = 4.0d0 + (4.0d0 * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.6e+174) || (!(z <= -1.85e+61) && ((z <= -0.000135) || !((z <= 1.5e+91) || (!(z <= 3.7e+111) && (z <= 1.06e+171)))))) {
tmp = (-4.0 * (z / y)) + 1.0;
} else {
tmp = 4.0 + (4.0 * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.6e+174) or (not (z <= -1.85e+61) and ((z <= -0.000135) or not ((z <= 1.5e+91) or (not (z <= 3.7e+111) and (z <= 1.06e+171))))): tmp = (-4.0 * (z / y)) + 1.0 else: tmp = 4.0 + (4.0 * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.6e+174) || (!(z <= -1.85e+61) && ((z <= -0.000135) || !((z <= 1.5e+91) || (!(z <= 3.7e+111) && (z <= 1.06e+171)))))) tmp = Float64(Float64(-4.0 * Float64(z / y)) + 1.0); else tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.6e+174) || (~((z <= -1.85e+61)) && ((z <= -0.000135) || ~(((z <= 1.5e+91) || (~((z <= 3.7e+111)) && (z <= 1.06e+171))))))) tmp = (-4.0 * (z / y)) + 1.0; else tmp = 4.0 + (4.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.6e+174], And[N[Not[LessEqual[z, -1.85e+61]], $MachinePrecision], Or[LessEqual[z, -0.000135], N[Not[Or[LessEqual[z, 1.5e+91], And[N[Not[LessEqual[z, 3.7e+111]], $MachinePrecision], LessEqual[z, 1.06e+171]]]], $MachinePrecision]]]], N[(N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{+174} \lor \neg \left(z \leq -1.85 \cdot 10^{+61}\right) \land \left(z \leq -0.000135 \lor \neg \left(z \leq 1.5 \cdot 10^{+91} \lor \neg \left(z \leq 3.7 \cdot 10^{+111}\right) \land z \leq 1.06 \cdot 10^{+171}\right)\right):\\
\;\;\;\;-4 \cdot \frac{z}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.6000000000000002e174 or -1.85000000000000001e61 < z < -1.35000000000000002e-4 or 1.50000000000000003e91 < z < 3.7000000000000003e111 or 1.06000000000000001e171 < z Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in z around inf 81.5%
*-commutative81.5%
Simplified81.5%
if -3.6000000000000002e174 < z < -1.85000000000000001e61 or -1.35000000000000002e-4 < z < 1.50000000000000003e91 or 3.7000000000000003e111 < z < 1.06000000000000001e171Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in x around inf 85.2%
Final simplification84.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* -4.0 (/ z y)) 1.0)) (t_1 (+ (* 4.0 (/ x y)) 1.0)))
(if (<= x -6000000000000.0)
t_1
(if (<= x 1.35e-260)
4.0
(if (<= x 6.2e-92)
t_0
(if (<= x 3.3e-48) 4.0 (if (<= x 1.5e+82) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = (-4.0 * (z / y)) + 1.0;
double t_1 = (4.0 * (x / y)) + 1.0;
double tmp;
if (x <= -6000000000000.0) {
tmp = t_1;
} else if (x <= 1.35e-260) {
tmp = 4.0;
} else if (x <= 6.2e-92) {
tmp = t_0;
} else if (x <= 3.3e-48) {
tmp = 4.0;
} else if (x <= 1.5e+82) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((-4.0d0) * (z / y)) + 1.0d0
t_1 = (4.0d0 * (x / y)) + 1.0d0
if (x <= (-6000000000000.0d0)) then
tmp = t_1
else if (x <= 1.35d-260) then
tmp = 4.0d0
else if (x <= 6.2d-92) then
tmp = t_0
else if (x <= 3.3d-48) then
tmp = 4.0d0
else if (x <= 1.5d+82) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (-4.0 * (z / y)) + 1.0;
double t_1 = (4.0 * (x / y)) + 1.0;
double tmp;
if (x <= -6000000000000.0) {
tmp = t_1;
} else if (x <= 1.35e-260) {
tmp = 4.0;
} else if (x <= 6.2e-92) {
tmp = t_0;
} else if (x <= 3.3e-48) {
tmp = 4.0;
} else if (x <= 1.5e+82) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (-4.0 * (z / y)) + 1.0 t_1 = (4.0 * (x / y)) + 1.0 tmp = 0 if x <= -6000000000000.0: tmp = t_1 elif x <= 1.35e-260: tmp = 4.0 elif x <= 6.2e-92: tmp = t_0 elif x <= 3.3e-48: tmp = 4.0 elif x <= 1.5e+82: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(-4.0 * Float64(z / y)) + 1.0) t_1 = Float64(Float64(4.0 * Float64(x / y)) + 1.0) tmp = 0.0 if (x <= -6000000000000.0) tmp = t_1; elseif (x <= 1.35e-260) tmp = 4.0; elseif (x <= 6.2e-92) tmp = t_0; elseif (x <= 3.3e-48) tmp = 4.0; elseif (x <= 1.5e+82) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (-4.0 * (z / y)) + 1.0; t_1 = (4.0 * (x / y)) + 1.0; tmp = 0.0; if (x <= -6000000000000.0) tmp = t_1; elseif (x <= 1.35e-260) tmp = 4.0; elseif (x <= 6.2e-92) tmp = t_0; elseif (x <= 3.3e-48) tmp = 4.0; elseif (x <= 1.5e+82) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -6000000000000.0], t$95$1, If[LessEqual[x, 1.35e-260], 4.0, If[LessEqual[x, 6.2e-92], t$95$0, If[LessEqual[x, 3.3e-48], 4.0, If[LessEqual[x, 1.5e+82], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -4 \cdot \frac{z}{y} + 1\\
t_1 := 4 \cdot \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -6000000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-260}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-92}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-48}:\\
\;\;\;\;4\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+82}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -6e12 or 1.49999999999999995e82 < x Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 67.9%
if -6e12 < x < 1.35000000000000003e-260 or 6.2000000000000002e-92 < x < 3.3e-48Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around inf 69.7%
if 1.35000000000000003e-260 < x < 6.2000000000000002e-92 or 3.3e-48 < x < 1.49999999999999995e82Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in z around inf 68.8%
*-commutative68.8%
Simplified68.8%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e+14) (not (<= x 4.1e-44))) (+ (* 4.0 (/ x y)) 1.0) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+14) || !(x <= 4.1e-44)) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 4.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-2.6d+14)) .or. (.not. (x <= 4.1d-44))) then
tmp = (4.0d0 * (x / y)) + 1.0d0
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+14) || !(x <= 4.1e-44)) {
tmp = (4.0 * (x / y)) + 1.0;
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+14) or not (x <= 4.1e-44): tmp = (4.0 * (x / y)) + 1.0 else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e+14) || !(x <= 4.1e-44)) tmp = Float64(Float64(4.0 * Float64(x / y)) + 1.0); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.6e+14) || ~((x <= 4.1e-44))) tmp = (4.0 * (x / y)) + 1.0; else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+14], N[Not[LessEqual[x, 4.1e-44]], $MachinePrecision]], N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+14} \lor \neg \left(x \leq 4.1 \cdot 10^{-44}\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if x < -2.6e14 or 4.09999999999999992e-44 < x Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 60.3%
if -2.6e14 < x < 4.09999999999999992e-44Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around inf 56.8%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e-55) (not (<= x 3.1e+77))) (+ 4.0 (* 4.0 (/ x y))) (+ 4.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-55) || !(x <= 3.1e+77)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-1.4d-55)) .or. (.not. (x <= 3.1d+77))) then
tmp = 4.0d0 + (4.0d0 * (x / y))
else
tmp = 4.0d0 + ((-4.0d0) * (z / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-55) || !(x <= 3.1e+77)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 + (-4.0 * (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e-55) or not (x <= 3.1e+77): tmp = 4.0 + (4.0 * (x / y)) else: tmp = 4.0 + (-4.0 * (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e-55) || !(x <= 3.1e+77)) tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(4.0 + Float64(-4.0 * Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.4e-55) || ~((x <= 3.1e+77))) tmp = 4.0 + (4.0 * (x / y)); else tmp = 4.0 + (-4.0 * (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e-55], N[Not[LessEqual[x, 3.1e+77]], $MachinePrecision]], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-55} \lor \neg \left(x \leq 3.1 \cdot 10^{+77}\right):\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + -4 \cdot \frac{z}{y}\\
\end{array}
\end{array}
if x < -1.39999999999999992e-55 or 3.09999999999999999e77 < x Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around 0 100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
if -1.39999999999999992e-55 < x < 3.09999999999999999e77Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in x around 0 93.3%
+-commutative93.3%
Simplified93.3%
Final simplification89.2%
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
return 4.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 4.0d0
end function
public static double code(double x, double y, double z) {
return 4.0;
}
def code(x, y, z): return 4.0
function code(x, y, z) return 4.0 end
function tmp = code(x, y, z) tmp = 4.0; end
code[x_, y_, z_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around inf 38.7%
Final simplification38.7%
herbie shell --seed 2024034
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))