
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 * ((x - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 * ((x - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ (- x y) z)) 2.0))
double code(double x, double y, double z) {
return (4.0 * ((x - y) / z)) - 2.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 * ((x - y) / z)) - 2.0d0
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) / z)) - 2.0;
}
def code(x, y, z): return (4.0 * ((x - y) / z)) - 2.0
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) / z)) - 2.0) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) / z)) - 2.0; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x - y}{z} - 2
\end{array}
Initial program 99.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* -4.0 (/ y z))) (t_1 (/ (* 4.0 x) z)))
(if (<= y -1.08e+33)
t_0
(if (<= y -4.1e-128)
t_1
(if (<= y 6.8e-249)
-2.0
(if (<= y 2.6e-105) t_1 (if (<= y 4.8e+78) -2.0 t_0)))))))
double code(double x, double y, double z) {
double t_0 = -4.0 * (y / z);
double t_1 = (4.0 * x) / z;
double tmp;
if (y <= -1.08e+33) {
tmp = t_0;
} else if (y <= -4.1e-128) {
tmp = t_1;
} else if (y <= 6.8e-249) {
tmp = -2.0;
} else if (y <= 2.6e-105) {
tmp = t_1;
} else if (y <= 4.8e+78) {
tmp = -2.0;
} else {
tmp = t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (-4.0d0) * (y / z)
t_1 = (4.0d0 * x) / z
if (y <= (-1.08d+33)) then
tmp = t_0
else if (y <= (-4.1d-128)) then
tmp = t_1
else if (y <= 6.8d-249) then
tmp = -2.0d0
else if (y <= 2.6d-105) then
tmp = t_1
else if (y <= 4.8d+78) then
tmp = -2.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -4.0 * (y / z);
double t_1 = (4.0 * x) / z;
double tmp;
if (y <= -1.08e+33) {
tmp = t_0;
} else if (y <= -4.1e-128) {
tmp = t_1;
} else if (y <= 6.8e-249) {
tmp = -2.0;
} else if (y <= 2.6e-105) {
tmp = t_1;
} else if (y <= 4.8e+78) {
tmp = -2.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -4.0 * (y / z) t_1 = (4.0 * x) / z tmp = 0 if y <= -1.08e+33: tmp = t_0 elif y <= -4.1e-128: tmp = t_1 elif y <= 6.8e-249: tmp = -2.0 elif y <= 2.6e-105: tmp = t_1 elif y <= 4.8e+78: tmp = -2.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-4.0 * Float64(y / z)) t_1 = Float64(Float64(4.0 * x) / z) tmp = 0.0 if (y <= -1.08e+33) tmp = t_0; elseif (y <= -4.1e-128) tmp = t_1; elseif (y <= 6.8e-249) tmp = -2.0; elseif (y <= 2.6e-105) tmp = t_1; elseif (y <= 4.8e+78) tmp = -2.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -4.0 * (y / z); t_1 = (4.0 * x) / z; tmp = 0.0; if (y <= -1.08e+33) tmp = t_0; elseif (y <= -4.1e-128) tmp = t_1; elseif (y <= 6.8e-249) tmp = -2.0; elseif (y <= 2.6e-105) tmp = t_1; elseif (y <= 4.8e+78) tmp = -2.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * x), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -1.08e+33], t$95$0, If[LessEqual[y, -4.1e-128], t$95$1, If[LessEqual[y, 6.8e-249], -2.0, If[LessEqual[y, 2.6e-105], t$95$1, If[LessEqual[y, 4.8e+78], -2.0, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -4 \cdot \frac{y}{z}\\
t_1 := \frac{4 \cdot x}{z}\\
\mathbf{if}\;y \leq -1.08 \cdot 10^{+33}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4.1 \cdot 10^{-128}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-249}:\\
\;\;\;\;-2\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+78}:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.08000000000000005e33 or 4.7999999999999997e78 < y Initial program 99.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 72.1%
if -1.08000000000000005e33 < y < -4.1e-128 or 6.7999999999999996e-249 < y < 2.5999999999999999e-105Initial program 99.9%
Taylor expanded in x around inf 58.9%
if -4.1e-128 < y < 6.7999999999999996e-249 or 2.5999999999999999e-105 < y < 4.7999999999999997e78Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around inf 61.3%
Final simplification64.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e+122) (not (<= x 2.4e+186))) (/ (* 4.0 x) z) (- (* -4.0 (/ y z)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+122) || !(x <= 2.4e+186)) {
tmp = (4.0 * x) / z;
} else {
tmp = (-4.0 * (y / z)) - 2.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.75d+122)) .or. (.not. (x <= 2.4d+186))) then
tmp = (4.0d0 * x) / z
else
tmp = ((-4.0d0) * (y / z)) - 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+122) || !(x <= 2.4e+186)) {
tmp = (4.0 * x) / z;
} else {
tmp = (-4.0 * (y / z)) - 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e+122) or not (x <= 2.4e+186): tmp = (4.0 * x) / z else: tmp = (-4.0 * (y / z)) - 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e+122) || !(x <= 2.4e+186)) tmp = Float64(Float64(4.0 * x) / z); else tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.75e+122) || ~((x <= 2.4e+186))) tmp = (4.0 * x) / z; else tmp = (-4.0 * (y / z)) - 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e+122], N[Not[LessEqual[x, 2.4e+186]], $MachinePrecision]], N[(N[(4.0 * x), $MachinePrecision] / z), $MachinePrecision], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+122} \lor \neg \left(x \leq 2.4 \cdot 10^{+186}\right):\\
\;\;\;\;\frac{4 \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\end{array}
\end{array}
if x < -2.7499999999999999e122 or 2.39999999999999995e186 < x Initial program 100.0%
Taylor expanded in x around inf 83.1%
if -2.7499999999999999e122 < x < 2.39999999999999995e186Initial program 99.5%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 84.3%
Final simplification84.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e+39) (not (<= y 2.65e-102))) (- (* -4.0 (/ y z)) 2.0) (- (* 4.0 (/ x z)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+39) || !(y <= 2.65e-102)) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = (4.0 * (x / z)) - 2.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 ((y <= (-6.8d+39)) .or. (.not. (y <= 2.65d-102))) then
tmp = ((-4.0d0) * (y / z)) - 2.0d0
else
tmp = (4.0d0 * (x / z)) - 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+39) || !(y <= 2.65e-102)) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = (4.0 * (x / z)) - 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.8e+39) or not (y <= 2.65e-102): tmp = (-4.0 * (y / z)) - 2.0 else: tmp = (4.0 * (x / z)) - 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e+39) || !(y <= 2.65e-102)) tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); else tmp = Float64(Float64(4.0 * Float64(x / z)) - 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.8e+39) || ~((y <= 2.65e-102))) tmp = (-4.0 * (y / z)) - 2.0; else tmp = (4.0 * (x / z)) - 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e+39], N[Not[LessEqual[y, 2.65e-102]], $MachinePrecision]], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+39} \lor \neg \left(y \leq 2.65 \cdot 10^{-102}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x}{z} - 2\\
\end{array}
\end{array}
if y < -6.7999999999999998e39 or 2.6500000000000001e-102 < y Initial program 99.2%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 87.2%
if -6.7999999999999998e39 < y < 2.6500000000000001e-102Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around inf 95.9%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.05e+114) (not (<= y 3.4e+78))) (* -4.0 (/ y z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e+114) || !(y <= 3.4e+78)) {
tmp = -4.0 * (y / z);
} else {
tmp = -2.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 ((y <= (-1.05d+114)) .or. (.not. (y <= 3.4d+78))) then
tmp = (-4.0d0) * (y / z)
else
tmp = -2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e+114) || !(y <= 3.4e+78)) {
tmp = -4.0 * (y / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e+114) or not (y <= 3.4e+78): tmp = -4.0 * (y / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e+114) || !(y <= 3.4e+78)) tmp = Float64(-4.0 * Float64(y / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.05e+114) || ~((y <= 3.4e+78))) tmp = -4.0 * (y / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e+114], N[Not[LessEqual[y, 3.4e+78]], $MachinePrecision]], N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+114} \lor \neg \left(y \leq 3.4 \cdot 10^{+78}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if y < -1.05e114 or 3.40000000000000007e78 < y Initial program 98.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 77.2%
if -1.05e114 < y < 3.40000000000000007e78Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around inf 51.1%
Final simplification59.9%
(FPCore (x y z) :precision binary64 -2.0)
double code(double x, double y, double z) {
return -2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -2.0d0
end function
public static double code(double x, double y, double z) {
return -2.0;
}
def code(x, y, z): return -2.0
function code(x, y, z) return -2.0 end
function tmp = code(x, y, z) tmp = -2.0; end
code[x_, y_, z_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 99.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around inf 37.7%
Final simplification37.7%
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
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 * (x / z)) - (2.0d0 + (4.0d0 * (y / z)))
end function
public static double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
def code(x, y, z): return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)))
function code(x, y, z) return Float64(Float64(4.0 * Float64(x / z)) - Float64(2.0 + Float64(4.0 * Float64(y / z)))) end
function tmp = code(x, y, z) tmp = (4.0 * (x / z)) - (2.0 + (4.0 * (y / z))); end
code[x_, y_, z_] := N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 + N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right)
\end{array}
herbie shell --seed 2023242
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:herbie-target
(- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))