
(FPCore (x y z) :precision binary64 :pre TRUE (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x - y) / (z - y) END code
\frac{x - y}{z - y}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x - y) / (z - y) END code
\frac{x - y}{z - y}
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (/ (- x y) (- z y))) (t_1 (/ x (- z y))))
(if (<= t_0 -20000.0)
t_1
(if (<= t_0 1e-16)
(/ (- x y) z)
(if (<= t_0 2.0) (/ y (- y z)) t_1)))))double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double t_1 = x / (z - y);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 1e-16) {
tmp = (x - y) / z;
} else if (t_0 <= 2.0) {
tmp = y / (y - z);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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 = (x - y) / (z - y)
t_1 = x / (z - y)
if (t_0 <= (-20000.0d0)) then
tmp = t_1
else if (t_0 <= 1d-16) then
tmp = (x - y) / z
else if (t_0 <= 2.0d0) then
tmp = y / (y - z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double t_1 = x / (z - y);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 1e-16) {
tmp = (x - y) / z;
} else if (t_0 <= 2.0) {
tmp = y / (y - z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / (z - y) t_1 = x / (z - y) tmp = 0 if t_0 <= -20000.0: tmp = t_1 elif t_0 <= 1e-16: tmp = (x - y) / z elif t_0 <= 2.0: tmp = y / (y - z) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / Float64(z - y)) t_1 = Float64(x / Float64(z - y)) tmp = 0.0 if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 1e-16) tmp = Float64(Float64(x - y) / z); elseif (t_0 <= 2.0) tmp = Float64(y / Float64(y - z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / (z - y); t_1 = x / (z - y); tmp = 0.0; if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 1e-16) tmp = (x - y) / z; elseif (t_0 <= 2.0) tmp = y / (y - z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000.0], t$95$1, If[LessEqual[t$95$0, 1e-16], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((x - y) / (z - y)) IN LET t_1 = (x / (z - y)) IN LET tmp_2 = IF (t_0 <= (2)) THEN (y / (y - z)) ELSE t_1 ENDIF IN LET tmp_1 = IF (t_0 <= (9999999999999999790977867240346035618411149408467364363417573258630000054836273193359375e-104)) THEN ((x - y) / z) ELSE tmp_2 ENDIF IN LET tmp = IF (t_0 <= (-2e4)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x - y}{z - y}\\
t_1 := \frac{x}{z - y}\\
\mathbf{if}\;t\_0 \leq -20000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{-16}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 z y)) < -2e4 or 2 < (/.f64 (-.f64 x y) (-.f64 z y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites53.5%
if -2e4 < (/.f64 (-.f64 x y) (-.f64 z y)) < 9.9999999999999998e-17Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites51.8%
if 9.9999999999999998e-17 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2Initial program 100.0%
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites52.7%
(FPCore (x y z) :precision binary64 :pre TRUE (let* ((t_0 (/ (- x y) (- z y))) (t_1 (/ x (- z y)))) (if (<= t_0 1e-61) t_1 (if (<= t_0 2.0) (/ y (- y z)) t_1))))
double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double t_1 = x / (z - y);
double tmp;
if (t_0 <= 1e-61) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = y / (y - z);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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 = (x - y) / (z - y)
t_1 = x / (z - y)
if (t_0 <= 1d-61) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = y / (y - z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double t_1 = x / (z - y);
double tmp;
if (t_0 <= 1e-61) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = y / (y - z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / (z - y) t_1 = x / (z - y) tmp = 0 if t_0 <= 1e-61: tmp = t_1 elif t_0 <= 2.0: tmp = y / (y - z) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / Float64(z - y)) t_1 = Float64(x / Float64(z - y)) tmp = 0.0 if (t_0 <= 1e-61) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(y / Float64(y - z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / (z - y); t_1 = x / (z - y); tmp = 0.0; if (t_0 <= 1e-61) tmp = t_1; elseif (t_0 <= 2.0) tmp = y / (y - z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-61], t$95$1, If[LessEqual[t$95$0, 2.0], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((x - y) / (z - y)) IN LET t_1 = (x / (z - y)) IN LET tmp_1 = IF (t_0 <= (2)) THEN (y / (y - z)) ELSE t_1 ENDIF IN LET tmp = IF (t_0 <= (10000000000000000395228123538898122123169379282217172946503413797519326445436778014303001284812088763590813033814098767741265594259325793402808839764107397274361943573239841498434543609619140625e-254)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x - y}{z - y}\\
t_1 := \frac{x}{z - y}\\
\mathbf{if}\;t\_0 \leq 10^{-61}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 z y)) < 1e-61 or 2 < (/.f64 (-.f64 x y) (-.f64 z y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites53.5%
if 1e-61 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2Initial program 100.0%
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites52.7%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (/ (- y x) y)))
(if (<= y -2.3213355743956985e-17)
t_0
(if (<= y 3.8673891431819095e-87) (/ x z) t_0))))double code(double x, double y, double z) {
double t_0 = (y - x) / y;
double tmp;
if (y <= -2.3213355743956985e-17) {
tmp = t_0;
} else if (y <= 3.8673891431819095e-87) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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 - x) / y
if (y <= (-2.3213355743956985d-17)) then
tmp = t_0
else if (y <= 3.8673891431819095d-87) then
tmp = x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - x) / y;
double tmp;
if (y <= -2.3213355743956985e-17) {
tmp = t_0;
} else if (y <= 3.8673891431819095e-87) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) / y tmp = 0 if y <= -2.3213355743956985e-17: tmp = t_0 elif y <= 3.8673891431819095e-87: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) / y) tmp = 0.0 if (y <= -2.3213355743956985e-17) tmp = t_0; elseif (y <= 3.8673891431819095e-87) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) / y; tmp = 0.0; if (y <= -2.3213355743956985e-17) tmp = t_0; elseif (y <= 3.8673891431819095e-87) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -2.3213355743956985e-17], t$95$0, If[LessEqual[y, 3.8673891431819095e-87], N[(x / z), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((y - x) / y) IN LET tmp_1 = IF (y <= (38673891431819094885403318309375528543623694643349420737358351555012295033582776355364773579241610915535033875773894486408398391025951413721328822529028666082754245438724342412985395970371362726390613938448097210327791817263687335071153938770294189453125e-340)) THEN (x / z) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-23213355743956984671546433862051546560035586032441808079784806295720045454800128936767578125e-108)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{y - x}{y}\\
\mathbf{if}\;y \leq -2.3213355743956985 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.8673891431819095 \cdot 10^{-87}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -2.3213355743956985e-17 or 3.8673891431819095e-87 < y Initial program 100.0%
Applied rewrites99.5%
Taylor expanded in z around 0
Applied rewrites51.5%
if -2.3213355743956985e-17 < y < 3.8673891431819095e-87Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites38.7%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (/ y (- y z))))
(if (<= y -1.0976763732990122e-41)
t_0
(if (<= y 3.8673891431819095e-87) (/ x z) t_0))))double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -1.0976763732990122e-41) {
tmp = t_0;
} else if (y <= 3.8673891431819095e-87) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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 / (y - z)
if (y <= (-1.0976763732990122d-41)) then
tmp = t_0
else if (y <= 3.8673891431819095d-87) then
tmp = x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -1.0976763732990122e-41) {
tmp = t_0;
} else if (y <= 3.8673891431819095e-87) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) tmp = 0 if y <= -1.0976763732990122e-41: tmp = t_0 elif y <= 3.8673891431819095e-87: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) tmp = 0.0 if (y <= -1.0976763732990122e-41) tmp = t_0; elseif (y <= 3.8673891431819095e-87) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); tmp = 0.0; if (y <= -1.0976763732990122e-41) tmp = t_0; elseif (y <= 3.8673891431819095e-87) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0976763732990122e-41], t$95$0, If[LessEqual[y, 3.8673891431819095e-87], N[(x / z), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (y / (y - z)) IN LET tmp_1 = IF (y <= (38673891431819094885403318309375528543623694643349420737358351555012295033582776355364773579241610915535033875773894486408398391025951413721328822529028666082754245438724342412985395970371362726390613938448097210327791817263687335071153938770294189453125e-340)) THEN (x / z) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-1097676373299012153341854168704378078335518237785186397527690064425959245104308786602546093259303999293001637138633697077239048667252063751220703125e-188)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
\mathbf{if}\;y \leq -1.0976763732990122 \cdot 10^{-41}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.8673891431819095 \cdot 10^{-87}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -1.0976763732990122e-41 or 3.8673891431819095e-87 < y Initial program 100.0%
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites52.7%
if -1.0976763732990122e-41 < y < 3.8673891431819095e-87Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites38.7%
(FPCore (x y z) :precision binary64 :pre TRUE (let* ((t_0 (/ (- x y) (- z y)))) (if (<= t_0 5e-17) (/ x z) (if (<= t_0 2.0) 1.0 (/ x z)))))
double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double tmp;
if (t_0 <= 5e-17) {
tmp = x / z;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = x / z;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x - y) / (z - y)
if (t_0 <= 5d-17) then
tmp = x / z
else if (t_0 <= 2.0d0) then
tmp = 1.0d0
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / (z - y);
double tmp;
if (t_0 <= 5e-17) {
tmp = x / z;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / (z - y) tmp = 0 if t_0 <= 5e-17: tmp = x / z elif t_0 <= 2.0: tmp = 1.0 else: tmp = x / z return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / Float64(z - y)) tmp = 0.0 if (t_0 <= 5e-17) tmp = Float64(x / z); elseif (t_0 <= 2.0) tmp = 1.0; else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / (z - y); tmp = 0.0; if (t_0 <= 5e-17) tmp = x / z; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-17], N[(x / z), $MachinePrecision], If[LessEqual[t$95$0, 2.0], 1.0, N[(x / z), $MachinePrecision]]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((x - y) / (z - y)) IN LET tmp_1 = IF (t_0 <= (2)) THEN (1) ELSE (x / z) ENDIF IN LET tmp = IF (t_0 <= (49999999999999998954889336201730178092055747042336821817087866293150000274181365966796875e-105)) THEN (x / z) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x - y}{z - y}\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{-17}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 z y)) < 4.9999999999999999e-17 or 2 < (/.f64 (-.f64 x y) (-.f64 z y)) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites38.7%
if 4.9999999999999999e-17 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites34.9%
(FPCore (x y z) :precision binary64 :pre TRUE 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = 1 END code
1
Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites34.9%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
(/ (- x y) (- z y)))