
(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 7 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) (- 1.0 y))))
double code(double x, double y, double z) {
return y + ((x / z) * (1.0 - 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 + ((x / z) * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return y + ((x / z) * (1.0 - y));
}
def code(x, y, z): return y + ((x / z) * (1.0 - y))
function code(x, y, z) return Float64(y + Float64(Float64(x / z) * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = y + ((x / z) * (1.0 - y)); end
code[x_, y_, z_] := N[(y + N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \frac{x}{z} \cdot \left(1 - y\right)
\end{array}
Initial program 91.5%
Taylor expanded in x around inf 96.6%
Taylor expanded in y around 0 93.1%
+-commutative93.1%
mul-1-neg93.1%
associate-/l*93.7%
sub-neg93.7%
*-lft-identity93.7%
associate-/l*93.6%
div-sub99.8%
sub-neg99.8%
metadata-eval99.8%
distribute-neg-in99.8%
associate-/l*96.6%
*-commutative96.6%
distribute-rgt-neg-in96.6%
distribute-frac-neg96.6%
*-commutative96.6%
associate-*r/100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
metadata-eval100.0%
sub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -55000000000.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 <= -55000000000.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 <= (-55000000000.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 <= -55000000000.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 <= -55000000000.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 <= -55000000000.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 <= -55000000000.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, -55000000000.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 -55000000000 \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 < -5.5e10 or 1 < y Initial program 82.0%
Taylor expanded in x around inf 92.8%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
if -5.5e10 < y < 1Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y -55000000000.0) (- y (* y (/ x z))) (if (<= y 1.0) (+ y (/ x z)) (* y (- 1.0 (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -55000000000.0) {
tmp = y - (y * (x / z));
} else if (y <= 1.0) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (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 <= (-55000000000.0d0)) then
tmp = y - (y * (x / z))
else if (y <= 1.0d0) then
tmp = y + (x / z)
else
tmp = y * (1.0d0 - (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -55000000000.0) {
tmp = y - (y * (x / z));
} else if (y <= 1.0) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -55000000000.0: tmp = y - (y * (x / z)) elif y <= 1.0: tmp = y + (x / z) else: tmp = y * (1.0 - (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -55000000000.0) tmp = Float64(y - Float64(y * Float64(x / z))); elseif (y <= 1.0) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(1.0 - Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -55000000000.0) tmp = y - (y * (x / z)); elseif (y <= 1.0) tmp = y + (x / z); else tmp = y * (1.0 - (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -55000000000.0], N[(y - N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -55000000000:\\
\;\;\;\;y - y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -5.5e10Initial program 85.7%
Taylor expanded in x around inf 93.6%
Taylor expanded in y around 0 93.6%
+-commutative93.6%
mul-1-neg93.6%
associate-/l*100.0%
sub-neg100.0%
*-lft-identity100.0%
associate-/l*100.0%
div-sub100.0%
sub-neg100.0%
metadata-eval100.0%
distribute-neg-in100.0%
associate-/l*93.6%
*-commutative93.6%
distribute-rgt-neg-in93.6%
distribute-frac-neg93.6%
*-commutative93.6%
associate-*r/100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
metadata-eval100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-rgt-in100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
*-lft-identity100.0%
distribute-rgt-neg-out100.0%
associate-*l/93.6%
*-commutative93.6%
unsub-neg93.6%
associate-*r/100.0%
Simplified100.0%
if -5.5e10 < y < 1Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
Simplified99.9%
if 1 < y Initial program 78.3%
Taylor expanded in x around inf 92.0%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y -7.2e+265) (/ (- (* y x)) z) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+265) {
tmp = -(y * 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 <= (-7.2d+265)) then
tmp = -(y * 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 <= -7.2e+265) {
tmp = -(y * x) / z;
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.2e+265: tmp = -(y * x) / z else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.2e+265) tmp = Float64(Float64(-Float64(y * 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 <= -7.2e+265) tmp = -(y * x) / z; else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.2e+265], N[((-N[(y * x), $MachinePrecision]) / z), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+265}:\\
\;\;\;\;\frac{-y \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -7.20000000000000005e265Initial program 84.9%
Taylor expanded in y around inf 84.9%
Taylor expanded in z around 0 84.9%
mul-1-neg84.9%
distribute-rgt-neg-out84.9%
Simplified84.9%
if -7.20000000000000005e265 < y Initial program 91.6%
Taylor expanded in z around inf 75.5%
Taylor expanded in x around 0 82.5%
+-commutative82.5%
Simplified82.5%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (if (<= y -4.1e-63) y (if (<= y 7.4e-26) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.1e-63) {
tmp = y;
} else if (y <= 7.4e-26) {
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 <= (-4.1d-63)) then
tmp = y
else if (y <= 7.4d-26) 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 <= -4.1e-63) {
tmp = y;
} else if (y <= 7.4e-26) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.1e-63: tmp = y elif y <= 7.4e-26: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.1e-63) tmp = y; elseif (y <= 7.4e-26) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.1e-63) tmp = y; elseif (y <= 7.4e-26) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.1e-63], y, If[LessEqual[y, 7.4e-26], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-63}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-26}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.0999999999999998e-63 or 7.3999999999999997e-26 < y Initial program 84.0%
Taylor expanded in x around 0 54.2%
if -4.0999999999999998e-63 < y < 7.3999999999999997e-26Initial program 99.9%
Taylor expanded in y around 0 79.6%
Final simplification66.1%
(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 91.5%
Taylor expanded in z around inf 74.7%
Taylor expanded in x around 0 80.8%
+-commutative80.8%
Simplified80.8%
Final simplification80.8%
(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 91.5%
Taylor expanded in x around 0 39.8%
Final simplification39.8%
(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 2023229
(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))