
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (- y (* (/ x z) (+ y -1.0))))
double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y - ((x / z) * (y + (-1.0d0)))
end function
public static double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
def code(x, y, z): return y - ((x / z) * (y + -1.0))
function code(x, y, z) return Float64(y - Float64(Float64(x / z) * Float64(y + -1.0))) end
function tmp = code(x, y, z) tmp = y - ((x / z) * (y + -1.0)); end
code[x_, y_, z_] := N[(y - N[(N[(x / z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - \frac{x}{z} \cdot \left(y + -1\right)
\end{array}
Initial program 88.9%
Taylor expanded in x around -inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
associate-/l*98.5%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- y) (/ z x))))
(if (<= x -3.4e+148)
t_0
(if (<= x 5e+203) (+ y (/ x z)) (if (<= x 2.6e+296) t_0 (/ x z))))))
double code(double x, double y, double z) {
double t_0 = -y / (z / x);
double tmp;
if (x <= -3.4e+148) {
tmp = t_0;
} else if (x <= 5e+203) {
tmp = y + (x / z);
} else if (x <= 2.6e+296) {
tmp = t_0;
} else {
tmp = x / z;
}
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) :: tmp
t_0 = -y / (z / x)
if (x <= (-3.4d+148)) then
tmp = t_0
else if (x <= 5d+203) then
tmp = y + (x / z)
else if (x <= 2.6d+296) then
tmp = t_0
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -y / (z / x);
double tmp;
if (x <= -3.4e+148) {
tmp = t_0;
} else if (x <= 5e+203) {
tmp = y + (x / z);
} else if (x <= 2.6e+296) {
tmp = t_0;
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): t_0 = -y / (z / x) tmp = 0 if x <= -3.4e+148: tmp = t_0 elif x <= 5e+203: tmp = y + (x / z) elif x <= 2.6e+296: tmp = t_0 else: tmp = x / z return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) / Float64(z / x)) tmp = 0.0 if (x <= -3.4e+148) tmp = t_0; elseif (x <= 5e+203) tmp = Float64(y + Float64(x / z)); elseif (x <= 2.6e+296) tmp = t_0; else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y / (z / x); tmp = 0.0; if (x <= -3.4e+148) tmp = t_0; elseif (x <= 5e+203) tmp = y + (x / z); elseif (x <= 2.6e+296) tmp = t_0; else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) / N[(z / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.4e+148], t$95$0, If[LessEqual[x, 5e+203], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.6e+296], t$95$0, N[(x / z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-y}{\frac{z}{x}}\\
\mathbf{if}\;x \leq -3.4 \cdot 10^{+148}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+203}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+296}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if x < -3.4000000000000003e148 or 4.99999999999999994e203 < x < 2.6000000000000001e296Initial program 87.0%
Taylor expanded in y around inf 57.4%
associate-/l*77.6%
associate-/r/70.3%
Simplified70.3%
Taylor expanded in z around 0 57.5%
associate-*r/57.5%
mul-1-neg57.5%
distribute-rgt-neg-in57.5%
associate-*r/64.8%
Simplified64.8%
Taylor expanded in x around 0 57.5%
mul-1-neg57.5%
*-commutative57.5%
associate-/l*72.1%
distribute-neg-frac72.1%
Simplified72.1%
if -3.4000000000000003e148 < x < 4.99999999999999994e203Initial program 89.2%
Taylor expanded in x around -inf 98.0%
mul-1-neg98.0%
unsub-neg98.0%
associate-/l*98.1%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 85.8%
mul-1-neg85.8%
distribute-frac-neg85.8%
Simplified85.8%
Taylor expanded in y around 0 85.8%
+-commutative85.8%
Simplified85.8%
if 2.6000000000000001e296 < x Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e+146) (not (<= x 2000000.0))) (* x (/ (- 1.0 y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+146) || !(x <= 2000000.0)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
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 <= (-9.5d+146)) .or. (.not. (x <= 2000000.0d0))) then
tmp = x * ((1.0d0 - y) / z)
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+146) || !(x <= 2000000.0)) {
tmp = x * ((1.0 - y) / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e+146) or not (x <= 2000000.0): tmp = x * ((1.0 - y) / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e+146) || !(x <= 2000000.0)) tmp = Float64(x * Float64(Float64(1.0 - y) / z)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.5e+146) || ~((x <= 2000000.0))) tmp = x * ((1.0 - y) / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+146], N[Not[LessEqual[x, 2000000.0]], $MachinePrecision]], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+146} \lor \neg \left(x \leq 2000000\right):\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -9.49999999999999926e146 or 2e6 < x Initial program 88.8%
Taylor expanded in x around -inf 92.4%
mul-1-neg92.4%
unsub-neg92.4%
associate-/l*99.9%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 87.7%
div-sub87.7%
Simplified87.7%
if -9.49999999999999926e146 < x < 2e6Initial program 88.9%
Taylor expanded in x around -inf 98.7%
mul-1-neg98.7%
unsub-neg98.7%
associate-/l*97.5%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 88.4%
mul-1-neg88.4%
distribute-frac-neg88.4%
Simplified88.4%
Taylor expanded in y around 0 88.4%
+-commutative88.4%
Simplified88.4%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 75.6%
Taylor expanded in x around -inf 91.6%
mul-1-neg91.6%
unsub-neg91.6%
associate-/l*96.7%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 98.4%
if -1 < y < 1Initial program 99.8%
Taylor expanded in x around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
associate-/l*100.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.7%
mul-1-neg98.7%
distribute-frac-neg98.7%
Simplified98.7%
Taylor expanded in y around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.4e+148) (* x (/ (- y) z)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e+148) {
tmp = x * (-y / z);
} else {
tmp = y + (x / z);
}
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 <= (-3.4d+148)) then
tmp = x * (-y / z)
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e+148) {
tmp = x * (-y / z);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.4e+148: tmp = x * (-y / z) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.4e+148) tmp = Float64(x * Float64(Float64(-y) / z)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.4e+148) tmp = x * (-y / z); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.4e+148], N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+148}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -3.4000000000000003e148Initial program 87.2%
Taylor expanded in y around inf 60.5%
associate-/l*76.5%
associate-/r/73.2%
Simplified73.2%
Taylor expanded in z around 0 60.5%
associate-*r/60.5%
mul-1-neg60.5%
distribute-rgt-neg-in60.5%
associate-*r/70.1%
Simplified70.1%
if -3.4000000000000003e148 < x Initial program 89.1%
Taylor expanded in x around -inf 97.4%
mul-1-neg97.4%
unsub-neg97.4%
associate-/l*98.3%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 82.4%
mul-1-neg82.4%
distribute-frac-neg82.4%
Simplified82.4%
Taylor expanded in y around 0 82.4%
+-commutative82.4%
Simplified82.4%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (<= y -5.8e-19) y (if (<= y 6.8e-45) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e-19) {
tmp = y;
} else if (y <= 6.8e-45) {
tmp = x / z;
} else {
tmp = 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 (y <= (-5.8d-19)) then
tmp = y
else if (y <= 6.8d-45) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e-19) {
tmp = y;
} else if (y <= 6.8e-45) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e-19: tmp = y elif y <= 6.8e-45: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e-19) tmp = y; elseif (y <= 6.8e-45) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.8e-19) tmp = y; elseif (y <= 6.8e-45) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e-19], y, If[LessEqual[y, 6.8e-45], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-19}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-45}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.8e-19 or 6.80000000000000008e-45 < y Initial program 78.2%
Taylor expanded in x around 0 47.9%
if -5.8e-19 < y < 6.80000000000000008e-45Initial program 99.9%
Taylor expanded in y around 0 74.9%
Final simplification61.2%
(FPCore (x y z) :precision binary64 (+ y (/ x z)))
double code(double x, double y, double z) {
return y + (x / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + (x / z)
end function
public static double code(double x, double y, double z) {
return y + (x / z);
}
def code(x, y, z): return y + (x / z)
function code(x, y, z) return Float64(y + Float64(x / z)) end
function tmp = code(x, y, z) tmp = y + (x / z); end
code[x_, y_, z_] := N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \frac{x}{z}
\end{array}
Initial program 88.9%
Taylor expanded in x around -inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
associate-/l*98.5%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 78.0%
mul-1-neg78.0%
distribute-frac-neg78.0%
Simplified78.0%
Taylor expanded in y around 0 78.0%
+-commutative78.0%
Simplified78.0%
Final simplification78.0%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 88.9%
Taylor expanded in x around 0 37.0%
Final simplification37.0%
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z): return (y + (x / z)) - (y / (z / x))
function code(x, y, z) return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (y + (x / z)) - (y / (z / x)); end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}
herbie shell --seed 2023340
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:herbie-target
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))